﻿Imports Microsoft.VisualBasic
Imports System
Imports System.Collections.Generic
Imports System.Text
Imports System.Data
Imports System.Data.OleDb

Public Class ExcelRead
    Public Shared Function getSheet(ByVal filePath As String, ByVal sheetName As String) As DataTable
        Dim sConnectionString As String = "Provider=Microsoft.Jet.OLEDB.4.0; Data Source=" & filePath & "; Extended Properties=Excel 8.0;"

        Dim objConn As New OleDbConnection(sConnectionString)

        objConn.Open()

        Dim objCmdSelect As New OleDbCommand("SELECT * FROM [" & sheetName & "$]", objConn)

        Dim objAdapter1 As New OleDbDataAdapter()

        objAdapter1.SelectCommand = objCmdSelect

        Dim dt As New DataTable()

        objAdapter1.Fill(dt)

        objConn.Close()
        Return dt
    End Function
End Class
